(function($){
    $.fn.validate = function(options){

        var fn_Format = function( opt_msg, opt_value ) {
            for (var i = 0; i < opt_value.length; i++) {
                opt_msg = opt_msg.replace("{"+i+"}",opt_value[i]);
            };
            $.each(opt_value, function( i, n ) {
                opt_msg = opt_msg.replace( new RegExp("\\{" + i + "\\}", "g"), function() {
                    return n;
                });
            });
            return opt_msg;
        }

        var defaults = {
            msgError_Length : "Please enter a value between {0} and {1} characters long.",
            //Message thong bao text rong
            msgError_Required : 'この項目は入力必須です。',
            //Gia tri mac dinh cua username
            username : {},
            //Gia tri mac dinh cua password va confirm password
            password: {},
            //Gia tri mac dinh cua fullname
            fullname : {},
            //Gia tri mac dinh cua address
            address : {},
            //Gia tri mac dinh cua email
            email : {},
            //Gia tri mac dinh cua phone
            phone : {},
            //Gia tri mac dinh cua fax
            fax : {},
            //Gia tri mac dinh cua postcode
            postcode : {},
            //Gia tri mac dinh cua website
            website : {},
            //gia tri mac dinh cua ip
            ip : {},
            //Gia tri mac dinh cua date
            date : {},
            //Gia tri mac dinh cho number
            number : {},
            //Gia tri mac dinh cua digits _ so thap phan
            digits : {},
            digits_f : {},
            //Gia tri mac dinh cua credit card
            creditCard : {},
            //Gia tri mac dinh cua money
            money : {},
            requirer: {}
        };
        var options = $.extend({},defaults, options);
        var _default = {
            //Gia tri mac dinh cua username
            username: {
                required : false,
                minLength : 7,
                maxLength : 20,
                msgError_Format : 'Please enter a valid username.(The characters a-z and A-Z and 0-9 and underline)',
                pattern_validate : '^[0-9a-zA-Z_]{7,20}$'
            },
            password: {
                required : false,
                minLength : 7,
                maxLength : 20,
                msgError_Format : 'Please enter a valid password.(The characters a-z and A-Z and 0-9 and @$)',
                pattern_validate : '^[0-9a-zA-Z@$]{7,20}$',
                msgError_Confirm : 'Please enter the same value again'
            },
            //Gia tri mac dinh cua fullname
            fullname : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : '',
                pattern_validate : ''
                //minLength : 10,
                //maxLength : 100,
                //msgError_Format : 'Please enter a valid fullname.(The characters a-z and A-Z and whitespace)',
                //pattern_validate : '^[a-zA-Z ]{10,100}$'
            },
            //Gia tri mac dinh cua address
            address : {
                required : false,
                minLength : 1,
                maxLength : 200,
                msgError_Format : 'Please enter a valid address.(The characters a-z and A-Z and 0-9 and whitespace:@-+/)',
                pattern_validate : '^[a-zA-Z:@ \\-\\+\\/]{1,200}$'
            },
            //Gia tri mac dinh cua email
            email : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : '正しいメールアドレスを入力して下さい。<br />例: infobgf@bgf.or.jp',
                pattern_validate : '[a-zA-Z0-9\\-_\\.]+@[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$'
            },
            //Gia tri mac dinh cua phone
            phone : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : "有効な電話番号を入力して下さい。<br /> 例: 03-6402-5312",
                pattern_validate : '^0[1-9][0-9]{0,3}\-[0-9]{1,4}\-[0-9]{4}$'
            },
            //Gia tri mac dinh cua fax
            fax : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : "有効なFax番号を入力して下さい。<br />例: 03-6402-5315",
                pattern_validate : '^0[1-9][0-9]{0,3}\-[0-9]{1,4}\-[0-9]{4}$'
            },
            //Gia tri mac dinh cua postcode
            postcode : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : '有効な郵便番号を入力して下さい。<br />例: 105-8480',
                pattern_validate : '^[0-9]{3}\-[0-9]{4}$'
            },
            //Gia tri mac dinh cua website
            website : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : '有効なURLを入力して下さい。',
                pattern_validate : '^((http|https):\\/\\/){0,1}(www\\.){0,1}[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+).+$'
            },
            //gia tri mac dinh cua ip
            ip : {
                required : false,
                minLength : 7,
                maxLength : 15,
                msgError_Format : 'Please enter a valid ip. (0.0.0.0)',
                pattern_validate : '^[0-9]{1,3}(\\.[0-9]{1,3}){3}$'
            },
            //Gia tri mac dinh cua date
            date : {
                startDate : "0001-02-10",
                endDate : "9999-11-11",
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : '正しい日時を入力して下さい。<br />(1973-01-01 or 1973/12/31)',
                pattern_validate : '^([0-9]{4}(\\/[0-9]{2}){2})|([0-9]{4}(\\-[0-9]{2}){2})$',
                msgError_WrongDate : 'Date input is wrong'
            },
            //Gia tri mac dinh cho number
            number : {
                required : false,
                minLength : "",
                maxLength : "",
                min : "",
                max : "",
                msgError_Format : '正しい数値を入力して下さい。',
                pattern_validate : '^[0-9]+$'
            },
            //Gia tri mac dinh cua digits _ so thap phan
            digits : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : '数値のみを入力して下さい。',
                pattern_validate : '^(\\-){0,1}[0-9]+(\\.[0-9]+){0,1}$'
            },
            digits_f : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : '数値のみを入力して下さい。',
                //pattern_validate : /^\$?\d+((,\d{3})+)?(\.\d{2})?$/
                pattern_validate : /^\$?\d+((,\d{1,3})+)?(\.\d{1,})?$/
            },
            //Gia tri mac dinh cua credit card
            creditCard : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : '正しいクレジットカード番号を入力して下さい。',
                pattern_validate : '^[0-9 \\-]+$',
                msgError_WrongCreditCard : 'Credit card input is wrong'
            },
            //Gia tri mac dinh cua money
            money : {
                required : false,
                minLength : "",
                maxLength : "",
                msgError_Format : '金額を入力して下さい。（数字、ドット及びカンマだけ含む)',
                pattern_validate : /^\$?\d+((,\d{3})+)?(\.\d{2})?$/
            },
            requirer : {
                required : true,
                minLength : "",
                maxLength : "",
                msgError_Format : "",
                pattern_validate : ""
            }
        };
        //Ham get thuoc tinh cho tung loai du lieu
        /**
        * Parameter:
        *   opt_type: tham so mac dinh du lieu can validate
        */
        var fn_GetProperty = function(opt_type,opt_property){
            var _lstArray = [];
            //Required
                if (opt_property[0] == "true") {
                    _lstArray.push(true);
                }else{
                    _lstArray.push(opt_type.required);
                }
                //min length
                if (opt_property[1] !== undefined && opt_property[1] !== "") {
                    _lstArray.push(opt_property[1]);

                }else{
                    _lstArray.push(opt_type.minLength);
                }
                //max length
                if (opt_property[2] !== undefined && opt_property[2] !== "") {
                    _lstArray.push(opt_property[2]);
                }else{
                    _lstArray.push(opt_type.maxLength)
                }
                //message error format
                if (opt_property[3] !== undefined && opt_property[3] !== "") {
                    _lstArray.push(opt_property[3]);
                }else{
                    _lstArray.push(opt_type.msgError_Format);
                }
                //alert(_lstArray[3]);
                //pattern validate
                if (opt_property[4] !== undefined && opt_property[4] !== "") {
                    _lstArray.push(opt_property[4]);
                }else{
                    _lstArray.push(opt_type.pattern_validate);
                }
                //Message error length
                _lstArray.push(fn_Format(options.msgError_Length,new Array(_lstArray[1],_lstArray[2])));

            return _lstArray;
        }
        //Ham thay doi css cua element den css loi va hien thi loi
        /**
        * Parameter:
        *   opt_err: span chua thong bao loi
        *   opt_div: div chua element hien tai
        *   opt_msg: thong bao loi de hien thi
        *   opt_show: show hay an loi
        */
        var fn_ShowError = function(opt_err,opt_div,opt_msg,opt_show){
            opt_err.attr("style", "display: inline; float: left; min-width: 200px");  
            //opt_err.html(opt_err.html()) 
            //opt_div.attr("style", "display: inline-block");
            if (opt_show) {
                opt_err.html(opt_msg).attr("class","msg_error");
                opt_div.attr("class","control-group error");
            }else{
                //Neu nhu element span co class la help-inline thi add class do la null
                if (opt_err.hasClass("msg_error")) {
                    opt_err.text("");
                };
                //Neu nhu element div co class la control-group error thi add class do la control-group
                if (opt_div.hasClass("control-group error")) {
                    opt_div.attr("class","control-group");
                };
            }
        }
        //Ham kiem tra nam nhuan
        /**
        * parameter:
        *   opt_value: gia tri cua nam can kiem tra nam nhuan
        */
        var fn_checkYear = function(opt_value){
            if (opt_value%4===0) {
                if (opt_value%100===0) {
                    if (opt_value%400===0) {
                        return true;
                    };
                }else{
                    return true;
                }
            };
            return false;
        }
        //Ham kiem tra ngay thang nhap vao co phai la ngay co gia tri hay khong
        /**
        * Parameter:
        *   opt_value: gia tri date can kiem tra
        */
        var fn_CheckDate = function(opt_value){
            //Neu chuoi dat nhap vao dung dinh dang
            if (opt_value.length==10) {

                var year = parseInt(opt_value.substring(0,4));
                var month = parseInt(opt_value.substring(5,7));
                var day = parseInt(opt_value.substring(8,10));
                //Neu nam nho hon nam bat dau va nam ket thuc mac dinh
                if (year < parseInt(options.date.startDate.substring(0,4)) || year > parseInt(options.date.endDate.substring(0,4))) {
                    return false;
                }
                //Neu nam bang voi nam bat dau mac dinh
                //Kiem tra thang
                if (year == parseInt(options.date.startDate.substring(0,4))) {
                    //Neu thang nho hon thang bat dau mac dinh tra ve false
                    if (month < parseInt(options.date.startDate.substring(5,7))) {
                        return false;
                    }
                    //Nguoc lai
                    else {
                        //Neu ngay nho hon ngay nho nhat mac dinh
                        if (day < parseInt(options.date.startDate.substring(8,10))) {
                            return false;
                        };
                    };
                }
                //Neu nam bang voi nam ket thuc mac dinh
                //Kiem tra thang
                if (year == parseInt(options.date.endDate.substring(0,4))) {
                    //Neu thang lon hon thang ket thuc mac dinh tra ve false
                    if (month > parseInt(options.date.endDate.substring(5,7))) {
                        return false;
                    }
                    //Nguoc lai
                    else {
                        //Neu ngay lon hon ngay ket thuc mac dinh
                        if (day > parseInt(options.date.endDate.substring(8,10))) {
                            return false;
                        };
                    }
                };
                //Kiem tra thang va ngay
                //Neu thang 2
                if (month == 2) {
                    //Neu la nam nhuan
                    if (fn_checkYear(year)) {
                        //Neu ngay tu 1 den 29 thi tra ve true
                        if (day>=1 && day<=29) {
                            return true;
                        }
                    }
                    //Neu khong phai la nam nhuan
                    else{
                        //Neu ngay tu 1 den 28 thi tra ve true
                        if (day>=1 && day<=28) {
                            return true;
                        }
                    }
                }
                //neu thang la thang co 31 ngay
                else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                    //Neu ngay tu 1 den 31 thi tra ve true
                    if (day>=1 && day<=31) {
                        return true;
                    };
                }
                //Neu thang co 30 ngay
                else if (month == 4 || month == 6 || month == 9 || month == 11) {
                    //Neu ngay tu 1 den 30 thi tra ve true
                    if (day>=1 && day<=30) {
                        return true;
                    };
                }
                return false;
            }else{
                return false;
            }
        }
        //Ham kiem tra tinh hop le cua credit card
        /**
        * Parameter:
        *   opt_value: gia tri credit card can validate
        */
        var fn_checkCreditCard = function(opt_value){
            var nCheck = 0,
                nDigit = 0,
                bEven = false;

            opt_value = opt_value.replace(/\D/g, "");

            for (var n = opt_value.length - 1; n >= 0; n--) {
                var cDigit = opt_value.charAt(n);
                nDigit = parseInt(cDigit, 10);
                if ( bEven ) {
                    if ( (nDigit *= 2) > 9 ) {
                        nDigit -= 9;
                    }
                }
                nCheck += nDigit;
                bEven = !bEven;
            }

            return (nCheck % 10) === 0;
        }
        //Ham so sanh value co bang nhau hay khong
        /**
        * parameter:
        *   opt_value1: gia tri cua field can duoc so sanh
        *   opt_value2: gia tri cua field de so sanh
        */
        var fn_EqualTo = function(opt_value1,opt_value2){
            return opt_value1 === opt_value2;
        }
        //Ham check property
        var fn_CheckProperty = function(opt_lst,opt_default){
            var _lstArray = [];
            var _lstDefault = [opt_default.required,opt_default.minLength,opt_default.maxLength,opt_default.msgError_Format,opt_default.pattern_validate];
            for (var i = 0; i < opt_lst.length; i++) {
                if (opt_lst[i] === undefined) {
                    _lstArray.push(_lstDefault[i]);
                }else {
                    if (i == 5) {
                        _lstArray.push(fn_Format(options.msgError_Length,new Array(_lstArray[1],_lstArray[2])));
                    }else {
                        _lstArray.push(opt_lst[i]);
                    }
                }

            };
            //alert(_lstArray[0]);
            return _lstArray;
        }
       //ham validate du lieu nguoi dung nhap vao co bo trong hay khong,
       //Gioi han chieu dai, dinh dang nhap vao
       /**
       * parameter:
       *    opt_value: gia tri cua input text truyen vao
       *    opt_err: element span de hien thi loi
       *    opt_div: element div de hien thi canh bao loi
       *    opt_type: xac dinh du lieu can validate thuoc loai du lieu nao
       * return: true hay false
       */
        var fn_ValidateInfo = function(opt_value,opt_err,opt_div,opt_type,opt_property){
            var _lstUncheck = [];
            var _lstArray = [];

            //Neu du lieu can validate la username
            if (opt_type == "username") {
                _lstUncheck = fn_GetProperty(options.username,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.username);
            }
            //Neu du lieu can validate la password
            else if (opt_type == "password") {
                _lstUncheck = fn_GetProperty(options.password,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.password);
            }
            //Neu du lieu can validate la fullname
            else if (opt_type == "fullname") {
                _lstUncheck = fn_GetProperty(options.fullname,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.fullname);
            }
            //Neu du lieu can validate la address
            else if (opt_type == "address") {
                _lstUncheck = fn_GetProperty(options.address,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.address);
            }
            //Neu du lieu can validate la email
            else if (opt_type == "email") {
                _lstUncheck = fn_GetProperty(options.email,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.email);
            }
            //Neu du lieu can validate la phone
            else if (opt_type == "phone") {
                _lstUncheck = fn_GetProperty(options.phone,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.phone);
            }
            //Neu du lieu can validate la fax
            else if (opt_type == "fax") {
                _lstUncheck = fn_GetProperty(options.fax,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.fax);
            }
            //Neu du lieu can validate la postcode
            else if (opt_type == "postcode") {
                _lstUncheck = fn_GetProperty(options.postcode,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.postcode);
            }
            //Neu du lieu can validate la website
            else if (opt_type == "website") {
                _lstUncheck = fn_GetProperty(options.website,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.website);
            }
            //Neu du lieu can validate la website
            else if (opt_type == "ip") {
                _lstUncheck = fn_GetProperty(options.ip,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.ip);
            }
            //Neu du lieu can validate la date
            else if (opt_type == "date") {
                _lstUncheck = fn_GetProperty(options.date,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.date);
            }
            //Neu du lieu can validate la number
            else if (opt_type == "number") {
                _lstUncheck = fn_GetProperty(options.number,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.number);
            }
            else if (opt_type == "digits") {
                _lstUncheck = fn_GetProperty(options.digits,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.digits);
            }

            else if (opt_type == "digits_f") {
                _lstUncheck = fn_GetProperty(options.digits_f,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.digits_f);
            }
            //Neu du lieu can validate la Credit card
            else if (opt_type == "credit card") {
                _lstUncheck = fn_GetProperty(options.creditCard,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.creditCard);
            }
            //Neu du lieu can validate la money
            else if (opt_type == "money") {
                _lstUncheck = fn_GetProperty(options.money,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.money);
            }
            else if (opt_type == "requirer"){
                _lstUncheck = fn_GetProperty(options.requirer,opt_property);
                _lstArray = fn_CheckProperty(_lstUncheck,_default.requirer);
            }
            //  alert(_lstArray[4]);
            //Validate data input
            if (_lstArray[0] == true) {
                //alert(_required);
                //Neu rong chua nhap du lieu
                if (opt_value == ""){
                    fn_ShowError(opt_err,opt_div,options.msgError_Required,true);
                    return false;
                }
            }
            if (opt_value !== "" && opt_value !== undefined) {
                //neu _minLength va _maxLength la khac rong
                if (_lstArray[1] != "" && _lstArray[2] != "") {
                        //Neu chieu dai nho hon gia tri minLength va lon hon gia tri maxLength
                    if(opt_value.length < _lstArray[1] || opt_value.length > _lstArray[2]){
                        fn_ShowError(opt_err,opt_div,_lstArray[5],true);
                        return false;
                    }
                }
                //Neu nhap vao sai dinh dang
                if(!new RegExp(_lstArray[4]).test(opt_value)){
                    fn_ShowError(opt_err,opt_div,_lstArray[3],true);
                    return false;
                }
                //Neu nhap vao dung dinh dang
                else{
                    fn_ShowError(opt_err,opt_div,"",false);
                    return true;
                }
            }else{
                fn_ShowError(opt_err,opt_div,"",false);
                return true;
            }
        }

        //Ham goi ham fn_ValidateInfo de tra ve ket qua validate
        /**
        * parameter:
        *   opt_vvField: lay ra element can validate
        *   opt_err: lay ra element span de hien thi thong cao loi
        *   opt_dvField: lay ra element div chua field
        *   opt_type: xac dinh du lieu can validate thuoc loai du lieu nao
        */
        var fn_CallValidate = function(opt_vvField,opt_err,opt_dvField,opt_type,opt_property){
            var _value = opt_vvField.val();
            return fn_ValidateInfo(_value,opt_err,opt_dvField,opt_type,opt_property);
        }

        //Ham get property tu form cho moi element
        /**
        * Parameter:
        *   opt_type: the input can validate
        */
        var fn_GetValue = function(opt_type){
            var propertyArray = [];
            propertyArray.push(opt_type.attr("data_required"));
            propertyArray.push(opt_type.attr("min_l"));
            propertyArray.push(opt_type.attr("max_l"));
            propertyArray.push(opt_type.attr("msgFormat"));
            propertyArray.push(opt_type.attr("v_pattern"));
            return propertyArray;
        }



        return this.each(function(){
            
            var k = $(this);
            var name;
            var _divControl;
            var _divGroupControl;
            var _spanError;
            var _type;
            var propertyArray = [];
            $('select').each(function(){
                var element = $(this);
                $(element).mouseup(function(){
                    if($(this).attr("data_required") === "true"){
                        _divControl = $($(this).parent().get(0));
                        _divGroupControl = $(_divControl.parent().get(0));
                        for (var j = 0; j < _divControl.children().length; j++) {
                            if ($(_divControl.children()[j]).attr("name") === "msg_error") {
                                _spanError = $(_divControl.children()[j]);
                            }
                        }
                        if($(element).val() ==="0"){
                            fn_ShowError(_spanError,_divGroupControl,options.msgError_Required,true);
                            
                            return false;
                        }else{
                            fn_ShowError(_spanError,_divGroupControl,options.msgError_Required,false);
                            return true;
                        }
                    }
                });
                k.submit(function(){
                    if($(element).attr("data_required") === "true"){
                        _divControl = $($(element).parent().get(0));
                        _divGroupControl = $(_divControl.parent().get(0));
                        for (var j = 0; j < _divControl.children().length; j++) {
                            if ($(_divControl.children()[j]).attr("name") === "msg_error") {
                                _spanError = $(_divControl.children()[j]);
                            }
                        }
                        if($(element).val() ==="0"){
                            fn_ShowError(_spanError,_divGroupControl,options.msgError_Required,true);
                            return false;
                        }else{
                            fn_ShowError(_spanError,_divGroupControl,options.msgError_Required,false);
                            return true;
                        }
                    }
                });
            });
            $('input').each(function(){
                var element = $(this);
                // $(element).keyup(function () {
                //     propertyArray = fn_GetValue($(this));
                //     name = $(this).attr("vvName");
                //     _divControl = $($(this).parent().get(0));
                //     _divGroupControl = $(_divControl.parent().get(0));
                //     for (var j = 0; j < _divControl.children().length; j++) {
                //         if ($(_divControl.children()[j]).attr("name") === "msg_error") {
                //             _spanError = $(_divControl.children()[j]);
                //         }
                //     }
                //     return fn_CallValidate($(this), _spanError, _divGroupControl, name, propertyArray);
                // });
                $(element).focusout(function () {
                    propertyArray = fn_GetValue($(this));
                    name = $(this).attr("vvName");
                    _divControl = $($(this).parent().get(0));
                    _divGroupControl = $(_divControl.parent().get(0));
                    for (var j = 0; j < _divControl.children().length; j++) {
                        if ($(_divControl.children()[j]).attr("name") === "msg_error") {
                            _spanError = $(_divControl.children()[j]);
                        }
                    }
                    return fn_CallValidate($(this), _spanError, _divGroupControl, name, propertyArray);
                });
                k.submit(function(){
                    propertyArray = fn_GetValue($(element));
                    name = $(element).attr("vvName");
                    if(name !== undefined){
                        _divControl = $($(element).parent().get(0));
                        _divGroupControl = $(_divControl.parent().get(0));
                        for (var j = 0; j < _divControl.children().length; j++) {
                            if ($(_divControl.children()[j]).attr("name") === "msg_error") {
                                _spanError = $(_divControl.children()[j]);
                            }
                        }
                        return fn_CallValidate($(element), _spanError, _divGroupControl, name, propertyArray);
                    }
                    if($(element).attr("type") === "radio"){
                        if($(element).attr("data_required") === "true"){
                            _divControl = $("div[name='dvRadio']");
                            _spanError = $("span[name='msg_error_radio']");
                            _element = $("div[name='dvRadio'] input:radio:checked");
                            if(_element.length === 0){
                                fn_ShowError(_spanError,_divControl,options.msgError_Required,true);
                                return false;
                            }else{
                                fn_ShowError(_spanError,_divControl,options.msgError_Required,false);
                                return true;
                            }
                        }
                    }
                    if($(element).attr("type") === "checkbox"){
                            _divControl = $("div[name='dvCheckbox']");
                            _spanError = $("span[name='msg_error_checkbox']");
                            _element = $("span[name='spCheckbox'] input:checkbox:checked");
                            if(_element.length === 0){
                                fn_ShowError(_spanError,_divControl,options.msgError_Required,true);
                                return false;
                            }else{
                                fn_ShowError(_spanError,_divControl,options.msgError_Required,false);
                                return true;
                            }
                    }
                });
                $(element).click(function(){
                    if($(this).attr("type") === "radio"){
                        if($(this).attr("data_required") === "true"){
                            _divControl = $("div[name='dvRadio']");
                            _spanError = $("span[name='msg_error_radio']");
                            _element = $("div[name='dvRadio'] input:radio:checked");
                            fn_ShowError(_spanError,_divControl,options.msgError_Required,false);
                        }
                    }
                    if($(this).attr("type") === "checkbox"){
                        _divControl = $("div[name='dvCheckbox']");
                        _spanError = $("span[name='msg_error_checkbox']");
                        _element = $("span[name='spCheckbox'] input:checkbox:checked");
                        if(_element.length === 0){
                            fn_ShowError(_spanError,_divControl,options.msgError_Required,true);
                        }else{
                            fn_ShowError(_spanError,_divControl,options.msgError_Required,false);
                        }
                        if($(this).attr("id") === "selectall"){
                            var checkAll = $(this);
                            var checkBox = $("span[name='spCheckbox']").find("input[type='checkbox']");
                            $(checkBox).each(function(){
                                $(this).prop('checked',$(checkAll).is(':checked') ? true: false);
                            });
                        }
                    }
                });
            });
            
        });
    };
})(jQuery);